package com.didd.core.dict.config;

import com.didd.core.dict.core.EntityDictProcessor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 字典映射组件自动装配方法拦截器 <br>
 *
 * @author diddd
 * @date: 2021/7/28 18:20
 */
public class EntityDictInterceptor implements MethodInterceptor {
    private static final Logger log = LoggerFactory.getLogger(EntityDictInterceptor.class);

    private EntityDictProcessor entityDictUtil;

    public EntityDictInterceptor(EntityDictProcessor entityDictUtil) {
        this.entityDictUtil = entityDictUtil;
    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        Object obj = methodInvocation.proceed();
        if (obj.getClass().isPrimitive()) {
            log.warn("基本类型不支持进行字段字典映射");
        } else {
            entityDictUtil.dictMapping(obj);
        }
        return obj;
    }
}
